import java.sql.*;
public class age{
    public static void main(String args[]) {
        Connection con=null;
        Statement sql;
        ResultSet rs;
        float agemax=0.0F,agemin=100.0F;
        String Namemax = null,Namemin = null;
        try{  Class.forName("com.mysql.jdbc.Driver"); //加载JDBC_MySQL驱动
        }
        catch(Exception e){}
        String uri = "jdbc:mysql://localhost:3306/world?useSSL=true";
        String user ="root";
        String password ="";
        try{
            con = DriverManager.getConnection(uri,user,password); //连接代码
        }
        catch(SQLException e){ }
        try {
            sql=con.createStatement();
            rs=sql.executeQuery("SELECT * FROM country"); //查询country表
            while(rs.next()) {
                String Name=rs.getString(2);
                float LifeExpectancy=rs.getFloat(8);
                if(LifeExpectancy>agemax){
                    agemax=LifeExpectancy;
                    Namemax=Name;
                }
                if(LifeExpectancy<agemin&&LifeExpectancy!=0){
                    agemin=LifeExpectancy;
                    Namemin=Name;
                }
            }
            System.out.printf("世界上的平均寿命最长的国家是%s\t,年龄是%f\n 最短的国家是%s\t,年龄是%f\t",Namemax,agemax,Namemin,agemin);
            con.close();
        }
        catch(SQLException e) {
            System.out.println(e);
        }
    }
}